package com.czjtxy.extraTerm.controller.deptmodule;

import com.czjtxy.extraTerm.entity.DO.Tdept;
import com.czjtxy.extraTerm.server.DeptService;
import com.czjtxy.extraTerm.serverImpl.DeptServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

/**
 * @author ZhangYing
 * @class 软件1903
 * @studentID 19852035
 * @date 2021/7/4
 */
@WebServlet(name = "SelectDeptServlet", value = "/SelectDeptServlet")
public class SelectDeptServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        super.doGet(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        DeptService deptService = new DeptServiceImpl();
        List<Tdept> tdepts = new ArrayList<>();
        try {
            tdepts = deptService.getPart(req.getParameter("name"));
            req.setAttribute("tdepts", tdepts);
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
        req.getRequestDispatcher("dept/dept.jsp").forward(req, resp);
    }
}
